﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using QLab.UX.Utilities;

namespace QLab.UX.Forms
{
    public partial class NewProjectForm : Form
    {
        public string SolutionName { get; set; }
        public string ProjectName { get; set; }
        public string LocationPath { get; set; }

        public NewProjectForm()
        {
            InitializeComponent();
            this.SolutionName = string.Empty;
            this.ProjectName = string.Empty;
            this.LocationPath = string.Empty;
        }

        private void buttonBrowse_Click(object sender, EventArgs e)
        {
            if (this.folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                this.textBoxLocation.Text = folderBrowserDialog.SelectedPath;
            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            string solutionName = this.textBoxSolutionName.Text.Trim();
            string projectName = this.textBoxProjectName.Text.Trim();
            string location = this.textBoxLocation.Text.Trim();

            if (!PathHelper.Instance.IsRegularFileName(solutionName))
            {
                MessageBox.Show("Not valid solution name.");
                return;
            }
            if (!PathHelper.Instance.IsRegularFileName(projectName))
            {
                MessageBox.Show("Not valid project name.");
                return;
            }
            if (!PathHelper.Instance.IsRegularFilePath(location))
            {
                MessageBox.Show("Not valid location.");
                return;
            }
            if (!Directory.Exists(location))
            {
                if (MessageBox.Show("Selected directory doesn't exsist. Do you want to create directory?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Directory.CreateDirectory(location);
                }
                else return;
            }

            this.SolutionName = solutionName;
            this.ProjectName = projectName;
            if (!location.EndsWith("\\"))
                location += "\\";
            this.LocationPath = location;

            this.DialogResult = DialogResult.OK;
        }
    }
}
